#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <poll.h>

int main(int argc, char *argv[])
{
	int fd;
    char *fliename;
    unsigned short databuf[3];
    unsigned short ir,als,ps;
    int ret;
  
    fliename = argv[1];
	
	/* 2. 打开文件 */
	fd = open(fliename, O_RDWR);   // | O_NONBLOCK

	if (fd < 0)
	{
		printf("can not open file %s, %d\n", fliename, fd);
		return -1;
	}

    while (1)
    {
        ret = read(fd,databuf,sizeof(databuf));
        if(ret == 0){
            ir = databuf[0];
            als = databuf[1];
            ps = databuf[2];
            printf("ir = %d, als = %d, ps = %d\r\n", ir, als, ps);
            }
        else{
            printf("read data bit wrong\r\n");
        }    
        usleep(200000);
    }
    close(fd);
    return 0;
}